#include <REGX52.H>



unsigned char KeyNum;

unsigned char Key(void)
{
	unsigned char Temp=0;
	Temp=KeyNum;
	KeyNum=0;
	return Temp;
}	


unsigned char Key_GetStape(void)
{
	unsigned char Key_state;
	if(P3_1==0)Key_state=1;
	if(P3_0==0)Key_state=2;
	if(P3_2==0)Key_state=3;
	if(P3_3==0)Key_state=4;
	return Key_state;
}


void Key_Loop(void)	
{
	static unsigned char Laststate,Nowstate;
	Laststate=Nowstate;
	Nowstate=Key_GetStape();
	if(Laststate==1&&Nowstate==0)
	{
		KeyNum=1;
	}
	if(Laststate==2&&Nowstate==0)
	{
		KeyNum=2;
	}
	if(Laststate==3&&Nowstate==0)
	{
		KeyNum=3;
	}
	if(Laststate==4&&Nowstate==0)
	{
		KeyNum=4;
	}
	
}